package com.tcoiss.webservice.apiServer;

import com.alibaba.fastjson.JSONObject;
import com.tcoiss.common.core.utils.DateUtils;
import com.tcoiss.webservice.domain.K3FormVo;
import com.tcoiss.webservice.domain.K3LoginVo;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

public class K3CloudInvoker extends Invoker{


    @Override
    public Map<String, Object> invoke(HttpAPIServer httpAPIServer,InvokeContext invokeContext) throws Exception {
        Map<String,Object> resultMap = new HashMap<>();
        String targerUrl = invokeContext.getEndpoint();
        String response = "";
        String reqBody = generateRequestString(invokeContext);
        invokeContext.setRequestTime(DateUtils.getTime());
        String requestType = invokeContext.getRequestType();

        //根据请求方式

        if(requestType.equals("login")){
            K3LoginVo loginVo = JSONObject.parseObject(reqBody,K3LoginVo.class);
            /*String dbId = jsonObject.get("dbId").toString();
            String user = jsonObject.get("user").toString();
            String pwd = jsonObject.get("pwd").toString();*/
            response = K3CloudServer.login(targerUrl,loginVo);

        }else{
            K3FormVo formVo = JSONObject.parseObject(reqBody,K3FormVo.class);
            /*String fromId = jsonObject.get("fromId").toString();
            String content = jsonObject.get("content").toString();*/
            response = K3CloudServer.operation(targerUrl,requestType,formVo);
        }

        return JSONObject.parseObject(response);
    }



}
